format '%s' expects type 'char *', but argument 3 has type 'char (*)[31]'
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,151
Rep:
To start off with please use code tags!
The warning says what it is the printf statement is expecteing a pointer to a sring of characters ( char* ) where as you are fiving it a pointer to a an array of 31 characters, char* is a zero terminated pointer to a string your array may not be, any way to remove the warning just type cast the pointer ie:
Code:
printf ( "%s\n",(char*)tempstr);
You can also specify the amount of characters to be printed if your array has no 0 terminating character, see the printf man page for full details, passing unterminated strings to printf can cause a segfault
Char with a Capital C is not char unless your compiler agrees that it is.
Code:
sprintf(tempstr, ", %s[%s]",bind +i,outidx);
As others have pointed out, you can cast to fix the warning. I recommend you do cast to fix the warning. Personally I enable as many warning options as I can and work towards warning free code. Also said, this doesn't mean the code is correct, but it helps to not be fooling one's self about the results which can occur. At the very least warnings will highlight a situation where the compiler is interpreting something differently than you envisioned and you get a chance to either do a cast or change the code to something else. And I'm assuming that the variable i came from somewhere?
My earlier points are that "Typed" and "Char" are not native (IMHO) C terms, I believe native terms would be "typedef" and "char" (lowercase 'c'). If there are other preprocessor files which give you these abstractions, fine. Just beware of them. And I can't really think of a reason why someone would want to have "Typed" for any real reason. Especially since it only saves you about one keystroke. You have two fewer characters in the name, but you had to shift to type one of those characters. I do get that things like Char are available in the more modern IDEs like Visual Studio or Eclipse. Jus tnot sure yet I agree.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,151
Rep:
Quote:
Originally Posted by rtmistler
... Personally I enable as many warning options as I can and work towards warning free code. ...
I do that as well, warnings can be annoying but they are there for a reason, it's always best to get rid of as many as possible ( by fixing the code mostly ).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.